package members;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MemberUpdate extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		
		try {
			String Mid= req.getParameter("updateID");
			String Mname = req.getParameter("updateName");
			int Mscore = Integer.parseInt( req.getParameter("updateScore"));			
			Class.forName("org.h2.Driver");
			Connection con = DriverManager.getConnection("jdbc:h2:~/retail","sa", "");			
			PreparedStatement ps = 
					con.prepareStatement("UPDATE MEMBER SET MEMBERNAME=?, MEMBERSCORE=? WHERE MEMBERID= ?");
		    ps.setString(1, Mname);
		    ps.setInt(2, Mscore);
		    ps.setString(3, Mid);

		    ps.executeUpdate();
		    ps.close();
			con.close();
			resp.sendRedirect("Member/MemberMain.jsp");					
		}catch (SQLException e) {			
			req.setAttribute("b", "SQL Exception: Insert Error!");
			req.getRequestDispatcher("Member/MemberError.jsp").forward(req, resp);							
		}catch (NumberFormatException e){
			req.setAttribute("b", "SQL Exception: Input Error!");
			req.getRequestDispatcher("Member/MemberError.jsp").forward(req, resp);		
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			

	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
